Stored Procedures [dbo].[asi_PurgePanelEditorSource]
Properties
PropertyValue
ANSI Nulls OnYes
Quoted Identifier OnYes
Parameters
NameData TypeMax Length (Bytes)
@panelNamenvarchar(100)200
@purgeDatabit1
SQL Script

-- Completely deletes all artifacts in the database for a named dynamic Panel Editor source  
CREATE PROCEDURE [dbo].[asi_PurgePanelEditorSource]
    @panelName nvarchar(100),
    @purgeData bit = 0
AS
BEGIN
    SET NOCOUNT ON
    DECLARE @documentKey uniqueidentifier;
    DECLARE @viewName sysname;
    DECLARE @sql nvarchar(1000);

    -- Drop BOD documents
    SELECT @documentKey = DocumentVersionKey FROM DocumentMain WHERE DocumentName = @panelName AND DocumentTypeCode = 'BUS' AND DocumentStatusCode = 40
    EXEC [dbo].[asi_DocumentDelete]  @documentKey, 1;
    SELECT @documentKey = DocumentVersionKey FROM DocumentMain WHERE DocumentName = @panelName AND DocumentTypeCode = 'BOD' AND DocumentStatusCode = 40
    EXEC [dbo].[asi_DocumentDelete]  @documentKey, 1;
    SELECT @documentKey = DocumentVersionKey FROM DocumentMain WHERE DocumentName = @panelName AND DocumentTypeCode = 'DBS' AND DocumentStatusCode = 40
    EXEC [dbo].[asi_DocumentDelete]  @documentKey, 1;
    -- Delete from RuleSource
    DELETE FROM [dbo].[RuleSourceDesign] WHERE RuleName = @panelName
    DELETE FROM [dbo].[RuleSourcePublish] WHERE RuleName = @panelName
    -- Drop associated views
    SELECT @viewName = TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME LIKE '%'+ @panelName
    WHILE @viewName IS NOT NULL
    BEGIN
        SET @sql = 'DROP VIEW ' + @viewName
        EXEC (@sql)
        SET @viewName = NULL
        SELECT @viewName = TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME LIKE '%'+ @panelName
    END    
    -- Drop Panel Definition and Object Metadata
    DELETE FROM [dbo].[PanelDefinition] WHERE [Name] = @panelName
    DELETE FROM [dbo].[ObjectMetaData] WHERE [ObjectName] = @panelName
    -- Delete from ComponentRegistry
    DELETE FROM ComponentRegistry
     WHERE [Name] = @panelName AND [InterfaceName] = 'IAtom' AND [Description] = 'Auto Generated'
    -- Purge Data for panel
    IF (@purgeData = 1)
    BEGIN
        DELETE FROM [dbo].[UserDefinedSingleInstanceProperty] WHERE [TableName] = @panelName
        DELETE FROM [dbo].[UserDefinedMultiInstanceProperty] WHERE [TableName] = @panelName
    END
    SET NOCOUNT OFF
END


GO
Uses